<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 50px;
            height: 50px;
            margin: 0 auto;
            text-align: center;
        }
    </style>
</head>
<body>
    <div>
        <input type="button" value="0">
    </div>
</body>
<script>
    window.onload = function(){
        var inp = document.getElementsByTagName("input")[0]
        // console.log(inp);
        function sum(){
            var sum = parseInt(inp.value)
            var i = 1
            return(sum += i)
        }
        inp.onclick = function() {
            // console.log(this.value);
            alert(sum())
            this.value = sum()
        }
    }
</script>
</html>